<template>
  <div class="wt-toast-wrapper">
    <div>
      温馨提示：{{ text }}
    </div>
    <div>
      {{ msg }}
    </div>
    <div>{{ txt }}</div>
    <wt-box />
    <div>
      <button @click="test">测试</button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'wt-toast',
  components: {},
  props: {
    text: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      msg: '啊啊啊啊',
      timer: null,
      txt: '哈哈'
    }
  },
  mounted() {
    console.log('22')
    // 第一次渲染完毕2s后，把渲染后的组件销毁掉
    this.timer = setTimeout(() => {
      this.$destroy() // 销毁组件
      clearTimeout(this.timer)
    }, 3000)
  },
  destroyed() {
    console.log('destroyed')
    clearTimeout(this.timer)
    // 还需要移除dom元素
    document.body.removeChild(this.$el)
  },
  methods: {
    test() {
      console.log('内部的')
    }
  },
  filters: {}
}
</script>
<style scoped>
.wt-toast-wrapper {
  width: 200px;
  height: 200px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid red;
  padding: 10px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
</style>
